﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex; 
using MediaMonitor.Common;

namespace MediaMonitor.Admin
{
    public partial class Select_Country : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillCountries();
            }
        }

        protected void FillCountries()
        {

            SqlDataReader rd = (SqlDataReader)Adex.Country.Query().SetSelectList("CountryID, CountryName").WHERE("Active", true).ExecuteReader();
            lstCountry.DataSource = rd;
            lstCountry.DataTextField = "CountryName";
            lstCountry.DataValueField = "CountryID";
            lstCountry.DataBind();
            lstCountry.Items.Insert(0, new ListItem("-Select Country-", "0"));

            if (AppUser.GetCountry() != 0)
            {
                Utility.SelectListItem(lstCountry, AppUser.GetCountry().ToString());
            }

        }

        protected void btnGo_Clicked(object sender, EventArgs e)
        {
            if (lstCountry.SelectedValue != "0")
            {
                AppUser.SetCountry(Utility.ToByte(lstCountry.SelectedValue), lstCountry.SelectedItem.Text);
                Response.Redirect("default.aspx");
            }
        }
    }
}